import { DEF } from "./consts";

export class UserInfo {

  public id: number;
  public username: string;
  public nickname: string;
  public sid: string;
  public token: string;

  public isOnline: boolean;
  public matching: boolean;
  public roomId: number;

  constructor(id: number, username: string, nickname: string, sid: string, token: string) {
    this.id = id;
    this.username = username;
    this.nickname = nickname;
    this.sid = sid;
    this.token = token;

    this.matching = false;
    this.isOnline = false;
    this.roomId = DEF.ROOM.ID_INVALID;
  }

  // online
  public online() {
    this.isOnline = true;
  }

  public offline() {
    this.isOnline = false;
  }

  // match
  public isMatching() {
    return this.matching && this.isOnline;
  }

  public match() {
    this.matching = true;
  }

  public unmatch() {
    this.matching = false;
  }

  // room
  public setRoom(roomId: number) {
    this.roomId = roomId;
  }
}
